//custom language sources
var lang_codes = 'ar,en,fr,pt,es,sw'
var source_language = 'en'

function translate_element(element, source_lang, target_lang){
	show_translation_message(target_lang, msgProcessingComment);
	if (source_lang == null){
		source_lang = "";
	}
	if(jq(element).length){
		if (source_lang != target_lang){
			google.language.translate(jq(element).html(), source_lang, target_lang, function(res){
					if(!res.error){
						jq(element).html(res.translation);
						show_translation_message(target_lang,msgFinished);
					}
				});
		}else{
			//restore content
			stored_element = jq(element, jq("#gTranslateStorage"));
			target_element = jq(element, jq("#col3_content"));
			jq(target_element).html(jq(stored_element).html());
		}
	}
}

function translate_comment(lang_code, element){
	cm_items = ["span.commentByLine", "div.commentBody",
	"div.commentactionbuttonsrow"]
	jq(cm_items, jq(element)).each(
		function(e){
			cm_box = jq(this);
			jq.each(cm_items,
				function(index, item){
					target_element = jq(item, jq(cm_box));
					if (target_element.length){
						//check for stored orginal data
						if (target_element.attr('rel') == null){
							target_element.attr('rel',jq(target_element).html());
						}else{
							target_element.html(target_element.attr('rel'));
						}
						//translate _content
						status = translate_element(target_element, 'auto', lang_code);
					}
				}
			);
		}
	);
}

function bindCommentTranslations(){
	//assume google translation machinery is loaded
	jQuery("span#gtranslate_comment").each(
		function(e){
			jq("span", jq(e)).each(
				function(ea){
					var ad = ea;
				}
			);
		}
	);
}

jQuery(document).ready(
	function(){
		bindCommentTranslations();
		
	}
);

function googleTranslateElementInit() {
	new google.translate.TranslateElement({
	pageLanguage:  source_language,
	includedLanguages: lang_codes,
	layout: google.translate.TranslateElement.InlineLayout.SIMPLE
  }, 'google_translate_element_container');
}
